/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2022-11-10
 * Time: 23:00
 */

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

class Solution {
    public boolean judge(TreeNode root, long low, long high){
        if(root==null){
            return true;
        }
        if(root.val<=low||root.val>=high){
            return false;
        }
        return judge(root.left,low,root.val)&&judge(root.right,root.val,high);
    }
    public boolean isValidBST(TreeNode root) {
        return judge(root,Long.MIN_VALUE,Long.MAX_VALUE);
    }
}
